﻿
$(function () {
    $("#wizard").scrollable({
        onSeek: function (event, i) {
            $("#status li").removeClass("active").eq(i).addClass("active");   //eq(i)获取匹配的元素
        },
        onBeforeSeek: function (event, i) {
            if (i == 2) {
                var card = $("#IDCard").val();
                var name = $("#Name").val();
                if (name == "") {
                    art.dialog.alert("请输入您的姓名！");
                    $("#Name").focus();
                    return false;
                }
                if (card == "") {
                    art.dialog.alert("请输入您的居民身份证号！");
                    $("#IDCard").focus();
                    return false;
                }

                if (name != "" && card != "") {
                    $.ajax({
                        type: "POST",
                        url: "IsDelegate.ashx",
                        data: "idcard=" + escape(card) + "&name=" + escape(name).val(),
                        success: function (msg) {
                            if (msg == "name") {
                                art.dialog.alert("姓名输入错误或不存在！");
                            }
                            else if (msg == "idcard") {
                                art.dialog.alert("身份证号输入有误或不存在！");
                            }
                        }
                    });
                }



            }
        }
    });
});
var xmlHttp = null;
try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
    try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e2) {
        xmlHttp = false;
    }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}

function getAjax() {
    var IDCard = document.getElementById("IDCard").value;
    var Name = document.getElementById("Name").value;
    xmlHttp.open("POST", "IsDelegate.ashx", true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            if (xmlHttp.responseText == "姓名输入错误或不存在！") {
                art.dialog.alert(xmlHttp.responseText);
                return false;
            }
            else if (xmlHttp.responseText == "身份证号输入有误或不存在！") {
                art.dialog.alert(xmlHttp.responseText);
                return false;
            }
            else {
                return true;
            }
        }
    }
    xmlHttp.send("idcard=" + IDCard + "&name=" + Name);
}










function check(object, Xb2) {
    if (Jmsfzhjy(object, Xb2) == "error1") {
        alert("您输入的身份证号不是数字信息!");
        $("#IDCard").focus();
        return;
    }
    if (Jmsfzhjy(Object, Xb2) == "error2") {
        alert("您输入的身份证号位数不正确!");
        $("#IDCard").focus();
        return;
    }
    if (Jmsfzhjy(Object, Xb2) == "error3") {
        alert("您输入的身份证号年份不正确!");
        $("#IDCard").focus();
        return;
    }
    if (Jmsfzhjy(Object, Xb2) == "error4") {
        alert("您输入的身份证号日期不正确!");
        $("#IDCard").focus();
        return;
    }
    if (Jmsfzhjy(Object, Xb2) == "error5") {
        alert("您输入的身份证号性别信息不正确!");
        $("#IDCard").focus();
        return;
    }
}

//判断居民身份证号输入是否正确1218
function Jmsfzhjy(strsfzh, xb) {
    var cd = strsfzh.length;
    var year = -1;
    var month = -1;
    var day = -1;
    for (kk = 0; kk < cd; kk++) {
        if (strsfzh.charAt(kk) > "9" || strsfzh.charAt(kk) < "0") {
            h1 = "error1";
            return h1;
        }
    }
    if (cd != 15 && cd != 18) {
        h1 = "error2";
        return h1

    }
    if (cd == 15) {
        s1 = strsfzh.substring(0, 6);
        s2 = "19" + strsfzh.substring(6, 15) + "0";

        strsfzh = s1 + s2;
    }
    year = issfzhYearValid(parseInt(strsfzh.substring(6, 10)));

    if (year == -1) {
        h1 = "error3"
        return h1
    }
    month = parseInt(strsfzh.substring(10, 12));
    day = isDayValid(year, month, parseInt(strsfzh.substring(12, 14)));
    if (day == "-1") {
        h1 = "error4"
        return h1
    }
    s = strsfzh.substring(16, 17);

    if ((s % 2 == 0 && xb == "男") || (s % 2 == 1 && xb == "女")) {
        h1 = "error5"
        return h1
    }
}

//判断居民身份证号年份的合法性
function issfzhYearValid(year) {
    var retyear = year;
    if (year == 0 || year < 1900 || year > 2100) retyear = -1;
    return retyear;
}
//判断日期和月份的合法性
function isDayValid(year, month, day) {
    var retday = day;
    if (day < 1 || day > 31 || month < 1 || month > 12) {
        retday = -1;
    }
    else {
        if (day == 31 && (month == 2 || month == 4 || month == 6 || month == 9 || month == 11)) {
            retday = -1;
        }
        else {
            if (month == 2 && day > 28 && !(day == 29 && year % 4 == 0 && (year % 100 !== 0 || year % 400 == 0))) {
                retday = -1
            }
        }
    }
    return retday;
}
function trim(string) {
    var temp = "";
    var temp1 = "";
    string = '' + string;
    splitstring = string.split(" ");
    for (i = 0; i < splitstring.length; i++)
        temp1 += splitstring[i];
    splitstring = temp1.split("?");
    for (i = 0; i < splitstring.length; i++)
        temp += splitstring[i];
    return temp;
}


















function isMobile(object) {
    //    var s = document.getElementById(object.id).value;
    var s = Object;
    var reg0 = /^13\d{5,9}$/;
    var reg1 = /^153\d{4,8}$/;
    var reg2 = /^159\d{4,8}$/;
    var reg3 = /^0\d{10,11}$/;
    var my = false;
    if (reg0.test(s)) my = true;
    if (reg1.test(s)) my = true;
    if (reg2.test(s)) my = true;
    if (reg3.test(s)) my = true;
    if (s != "") {
        if (!my) {
            art.dialog.alert('请输入正确的手机号码');
            object = "";
            $("#mobile").focus();
        }
    }
}
